import Utils from '@/utils';
import configJson from '../../pluginTemp/config.json';

const { onMounted, onUnmounted } = Vue3;

export default function useRegister(props = {}, actions = {}, eventActionDefinitions = {}) {
  const { customConfig = {}, componentId } = props;

  const Event_Center_getName = () => {
    const requirementNumber = configJson['requirement-number'];
    return customConfig.id || requirementNumber || Utils.generateUUID();
  };

  onMounted(() => {
    window.componentCenter?.register(
      componentId,
      'comp',
      {
        Event_Center_getName,
        ...actions,
      },
      eventActionDefinitions,
    );
  });

  onUnmounted(() => window.componentCenter?.removeInstance(componentId));
}
